package com.example.demo.arithmetic;/**
 * Created by kete on 2018-11-27.
 */

import java.util.HashSet;
import java.util.Set;

/**
 * 作者：kete
 * 创建时间：2018-11-27 11:10
 * 功能描述：
 * 版本：
 */
public class HappyNum {

    public static boolean isHappy(Integer number){
        Set<Integer> set = new HashSet<>(30);
        while (number!=1){
            int sum = 0;

            while (number>0){
               sum += (number%10)*(number%10);
               number = number/10;
            }

            if(set.contains(sum))
                return false;
            else
                set.add(sum);

            number = sum;

        }

        return true;
    }
}
